<?php
namespace Admin\Controller;
use Think\Controller;

class CatController extends Controller{
	public function Catadd(){

		if (!$_POST) {
			$this->display();
		}else{
			$CatModel = D('Cat');
			$CatModel -> add($_POST);
			$this->redirect('admin/cat/catlist');
		}
		
	}


	public function Catlist(){
		$CatModel = D('Cat');
		$Catlist = $CatModel->order('cat_id asc')->select();
		$this->assign('list',$Catlist);
		$this->display();
	}


	public function catdel(){
		$catmodel = D('cat');
		$data = $catmodel -> delete($_GET['cat_id']);

		if ($data) {
			$this->redirect('admin/cat/catlist');
		}else{
			echo "代码没写好";
		}

	}

	public function catupdate(){		
		$catmodel = D('cat');
		

		if (!$_POST) {
		$cat_id=$_GET['cat_id'];
		$cat = $catmodel->find($cat_id);
		$this->assign('catname',$cat);
		$this->display();
		}else{
		$a=$_GET['cat_id'];
		$catmodel->where("cat_id=$a")->save($_POST);
		$this->redirect('admin/cat/catlist');
		}
		
	}

}
?>